﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>班级修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <h3 style="margin:15px 0;text-align: center;color: #008C8C">若输入项为空，则该项不更新</h3>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>题目类别</label>
            <div id="major" style="width: 25%;border:solid 1px #d1dade" class="layui-form-label"></div>
            <div class="layui-input-block">
                <input type="radio" name="major" value="Java" lay-skin="primary" title="Java" checked="">
                <input type="radio" name="major" value="HTML5" lay-skin="primary" title="HTML5">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>题目级别</label>
            <div id="level" style="width: 25%;border:solid 1px #d1dade" class="layui-form-label"></div>
            <div class="layui-input-block">
                <input type="radio" name="level" value="1" lay-skin="primary" title="简单" checked="">
                <input type="radio" name="level" value="2" lay-skin="primary" title="普通">
                <input type="radio" name="level" value="3" lay-skin="primary" title="困难">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">题目来源</label>
            <div id="source" style="width: 25%;border:solid 1px #d1dade" class="layui-form-label"></div>
            <div class="layui-input-block" >
                <input type="text" name="source" style="width: 69%" placeholder="请输入题目来源" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">题目类型</label>
            <div id="seg" style="width: 25%;border:solid 1px #d1dade" class="layui-form-label"></div>
            <div class="layui-input-block">
                <input type="text" name="seg" style="width: 69%" placeholder="请输入题目类型" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">题目</label>
            <div id="title" style="width: 25%;border:solid 1px #d1dade" class="layui-form-label"></div>
            <div class="layui-input-block">
                <input type="text" name="title"  style="width: 69%" placeholder="请输入题目" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">选项A</label>
            <div id="choiseA" style="width: 25%;border:solid 1px #d1dade" class="layui-form-label"></div>
            <div class="layui-input-block">
                <input type="text" name="choiseA" style="width: 69%" placeholder="请输入选项A" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">选项B</label>
            <div id="choiseB" style="width: 25%;border:solid 1px #d1dade" class="layui-form-label"></div>
            <div class="layui-input-block">
                <input type="text" name="choiseB" style="width: 69%" placeholder="请输入选项B" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">选项C</label>
            <div id="choiseC" style="width: 25%;border:solid 1px #d1dade" class="layui-form-label"></div>
            <div class="layui-input-block">
                <input type="text" name="choiseC" style="width: 69%" placeholder="请输入选项C" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">选项D</label>
            <div id="choiseD" style="width: 25%;border:solid 1px #d1dade" class="layui-form-label"></div>
            <div class="layui-input-block">
                <input type="text" name="choiseD" style="width: 69%" placeholder="请输入选项D" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">答案</label>
            <div id="correct" style="width: 25%;border:solid 1px #d1dade" class="layui-form-label"></div>
            <div class="layui-input-block" >
                <input type="text" name="correct" style="width: 69%" placeholder="请输入答案" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="btn" type="button" class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script>
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return 1;
    }

    // console.log("id="+getUrlParam("id"))
    // 填充用户信息
    $.ajax({
        type: "get",
        url: "/choose/getQuestionById",
        data: "id=" + getUrlParam("id"),
        success: function (res) {
            console.log(res.data)
            $("#major").text(res.data.major);
            $("#level").text(res.data.level)
            $("#source").text(res.data.source);
            $("#seg").text(res.data.seg);
            $("#title").text(res.data.title);
            $("#choiseA").text(res.data.choiseA);
            $("#choiseB").text(res.data.choiseB);
            $("#choiseC").text(res.data.choiseC);
            $("#choiseD").text(res.data.choiseD);
            $("#correct").text(res.data.correct);
        }
    })

    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(add)', function (data) {
            data.field.id = getUrlParam("id");
            $.ajax({
                url: '/choose/questionUpdate',
                data: data.field,
                type: "post",
                success: function () {
                    // var index = layer.alert(JSON.stringify(data.field), {
                    //     title: '最终的提交信息'
                    // }, function () {
                    //
                    //     // 关闭弹出层
                    //     layer.close(index);

                    alert("修改题目成功")

                    //重新加载父页面
                    parent.location.reload();

                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);

                    // });
                }
            })
            return false;
        });
    });
</script>
</body>

</html>